//
//  MyControl.m
//  Assignment 3
//
//  Created by nthu on 11/11/16.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "MyControl.h"
#import "Polygons.h"

@implementation MyControl
@synthesize polyView;

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
        anglenum = 3;
        strokeSize = 0.0;
    }
    
    return self;
}

-(IBAction) changeNumber :(id)sender
{
    int sliderValue = slider.value;
    number.text = [NSString stringWithFormat:@"%d",sliderValue]; 
    strokeSize = sliderValue;
    self.polyView.qq = anglenum;
    self.polyView.stroke = strokeSize/5;
    [self.polyView setNeedsDisplay];

}

-(IBAction) plusAngle:(id)sender
{
    anglenum = anglenum + 1;
    angleNumber.text =[NSString stringWithFormat:@"%d",anglenum];
    self.polyView.qq = anglenum;
    self.polyView.stroke = strokeSize/5;
    CGRect frame = self.polyView.frame;
    int start = frame.origin.x;
    frame.origin.x = 500;
    self.polyView.frame=frame;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    frame.origin.x = start;
    self.polyView.frame = frame;
    [UIView commitAnimations];
    [self.polyView setNeedsDisplay];
    [self showName:anglenum];
}
-(IBAction) minusAngle:(id)sender
{
    if(anglenum > 3){
        anglenum = anglenum - 1;
        angleNumber.text =[NSString stringWithFormat:@"%d",anglenum];
    }
    self.polyView.qq = anglenum;
    self.polyView.stroke = strokeSize/5;
    [UIView animateWithDuration:0.3 animations:^{
        self.polyView.alpha = 0.0;
        self.polyView.alpha = 1.0;
    }];
    [self.polyView setNeedsDisplay];
    [self showName:anglenum];

}

-(void) showName:(int)side
{
    NSString *ch;
    NSString *en;
    switch (side) {
        case 3:
            ch = @"三角形";
            en = @"Triangle";
            break;
        case 4:
            ch = @"正方形";
            en = @"Squre";
            break;
        case 5:
            ch = @"五邊形";
            en = @"Pentagon";
            break;
        case 6:
            ch = @"六邊形";
            en = @"Hexagon";
            break;
        case 7:
            ch = @"七邊形";
            en = @"Heptagon";
            break;
        case 8:
            ch = @"八邊形";
            en = @"Octagonal";
            break;
        case 9:
            ch = @"九邊形";
            en = @"Nine-shaped";
            break;
        case 10:
            ch = @"十邊形";
            en = @"Decagonal";
            break;
        default:
            ch = @"接近圓形";
            en = @"Almost circle";
            break;
    }
    chinese.text = [NSString stringWithFormat:@"%@",ch];
    english.text = [NSString stringWithFormat:@"%@",en];
}

-(int) getAngleNum
{
    return anglenum;
}
@end
